import React, { Component } from 'react';
import '../../components/Header/Header.scss'
import pic from '../../assets/logo.png'
import Nav from '../../components/Nav/Nav';
import Swipe from '../../components/Swiper/Swipe';
import { PullToRefresh, List } from 'antd-mobile'
import { sleep } from 'antd-mobile/es/utils/sleep'
import Catelist from '../../components/Catelist/Catelist';
import Seckill from '../../components/Seckill/Seckill';

class Home extends Component {
    constructor(props) {
        super(props)
        this.state = {
            name: null,
            token: '',
        }
    }
    async componentDidMount() {
        if (this.props.location.state) {
            this.setState({ name: this.props.location.state.city })
        }
        this.setState({ token: localStorage.getItem('token') })
    }
    login() {
        if (localStorage.getItem('token')) {
            this.props.history.push('/index/mine')
        } else {
            this.props.history.push('/login')
        }
    }
    city() {

        this.props.history.push({ pathname: '/city' })
    }
    render() {
        return (
            <div className='home'>
                <PullToRefresh
                    damping={200}
                    onRefresh={async () => {
                        await sleep(1000)
                    }}
                >

                    <div className='header'>
                        <span onClick={() => { this.city() }}>{this.props.location.state == null ? '西安' : this.props.location.state.city}</span>
                        <input type="text" placeholder='立柜式空调' onClick={() => { this.props.history.push('/hotseach') }} />
                        <span onClick={() => { this.login() }}>{this.state.token == '' ? '登录' : '我的'}</span>
                        <div className="hg">
                            <img src={pic} alt="" />
                            <span className='iconfont icon-shuxian'></span>
                            <span className='iconfont icon-sousuo'></span>
                        </div>
                    </div>
                    <Swipe />
                    <Nav />
                    < Seckill />
                    <Catelist />
                </PullToRefresh>

            </div>
        );
    }
}

export default Home;